﻿@{
    ViewBag.Title = "AddForm";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script>
    var organizeid = request('organizeid');
    var Category = request('Category');
    var RoomId = "", _RoomId = "", _State = request('Category');
    var Data = [];
    var Idlst = [], Lst = [];
    var RoomPstructIdStr = "";
    var RoomType = "";
    $(function () {
        GetTree();
        GetGrid();
    })
    function GetTree() {
        $.ajax({
            url: "../../ResourceManage/RS_PStructPublish/GetTree?OrganizeId=" + organizeid + "&State=" + Category ,
            data: { lst: JSON.stringify(Idlst) },
            type: 'post',
            dataType: "json",
            success: function (item) {
                var item = {
                    data: item,
                     height: $(window).height() - 55,
                    showcheck: true,
                    oncheckboxclick: function (item) { 
                    }
                };
                $("#itemTree1").treeview(item);
            }
        })
    }
    function GetGrid() {
        var selectedRowIndex = 0;
        $gridTable = $("#gridTable");
        $gridTable.jqGrid({
            datatype: "json",
            height: $(window).height() - 50,
            autowidth: true,
            unwritten: false,
            colModel: [
                { label: "主键", name: "Id", hidden: true },               
                { label: "PStructId", name: "PStructId", hidden: true },
                { label: "小区名称", name: "", hidden: true },
                { label: "起租日期", name: "EMoveInDate", hidden: true },
                { label: "房屋名称", name: "RoomName", hidden: true },
                { label: "月租金", name: "MonthlyRent", hidden: true },
                { label: "房屋地址", name: "Pavilionion", index: "Pavilionion", width: 200, align: "center", sortable: false },
                { label: "房屋编号", name: "RoomCode", index: "RoomCode", width: 80, align: "center", sortable: false },
                { label: "房屋状态", name: "RoomState", index: "RoomState", width: 80, align: "center", hidden: true },
                {
                    label: "房屋状态", name: "RoomStateStr", index: "RoomStateStr", width: 80, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        switch (rowObject.RoomState) {
                            case "0":
                            case 0: return "准备房";
                            case "1":
                            case 1: return "待租";
                            case "2":
                            case 2: return "已选取";
                            case "3":
                            case 3: return "已租";
                            case "4":
                            case 4: return "自用";
                            case "5":
                            case 5: return "已售";
                            case "6":
                            case 6: return "续租中";
                            case "7":
                            case 7: return "维修中";
                            default: return "---";

                        }
                    }
                },
                {
                    label: "户型", name: "RoomType", index: "RoomType", width: 80, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case "1": case 1: return "一室";
                            case "2": case 2: return "一室一厅";
                            case "3": case 3: return "二室";
                            case "4": case 4: return "二室一厅";
                            case "5": case 5: return "三室";
                            case "6": case 6: return "三室一厅";
                            case "7": case 7: return "四室";
                            case "8": case 8: return "五室";
                            default: return cellvalue;

                        }
                    }
                },
                { label: "建筑面积", name: "Area", index: "Area", width: 50, align: "center", sortable: false },
                {
                    label: "起租日期", name: "EMoveInDate", index: "EMoveInDate", width: 100, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd');
                    }
                },
                { label: "PC发布状态", name: "IsPublish", index: "IsPublish", width: 200, align: "center", hidden: true },
                { label: "是否发布到PC", name: "IsPublishToPC", index: "IsPublishToPC", width: 200, align: "center", hidden: true },
                { label: "其他发布状态", name: "IsPublishOther", index: "IsPublishOther", width: 200, align: "center", hidden: true },
                { label: "是否发布其他平台", name: "IsPublishToOther", index: "IsPublishToOther", width: 200, align: "center", hidden: true },
                {
                     label: "操作状态", name: "IsPublishStr", index: "IsPublishStr", width: 200, align: "center", sortable: false,
                     formatter: function (cellvalue, options, rowObject) {
                         debugger;
                         var str = "发布撤回情况：";
                         if (rowObject.IsPublishToPC == 1) {
                             str += "已操作pc端";
                             switch (rowObject.IsPublish) {
                                 case 1:
                                 case 2: str += "且发布成功"; break;
                                 case 3: str += "且发布失败"; break;
                                 case 4: str += "且成功撤回"; break;
                                 case 5: str += "且撤回失败"; break;
                                 default: str += ""; break;
                             }
                         }
                         else {
                             str += "未操作pc端";
                         }

                         if (rowObject.IsPublishToOther == 1) {
                             str += "；已操作其他平台";
                             switch (rowObject.IsPublishOther) {
                                 case 1:
                                 case 2: str += "且发布成功"; break;
                                 case 3: str += "且发布失败"; break;
                                 case 4: str += "且成功撤回"; break;
                                 case 5: str += "且撤回失败"; break;
                                 default: str += ""; break;
                             }
                         }
                         else {
                             str += "；未操作其他平台：";
                         }

                         return str;
                     }
                 },
                { label: "BillId", name: "BillId", hidden: true },
                { label: "RoomDetail", name: "RoomDetail", hidden: true }

            ],
            viewrecords: true,
            rowNum: 1000,
            rownumbers: true,
            gridview: true,
            pager: "#gridPager",
            sortname: 'Date',
            sortorder: 'desc',
            multiselect: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                _RoomId = $gridTable.getCell(selectedRowIndex, "Id");              
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);

            },           
        })
    }
    function btn_add() {       
        $(".bbit-tree-node-cb").each(function () {
            if ($(this).attr("src").indexOf("checkbox_1") > 0) {
                var s = $(this).next().next().children().eq(0).attr("data-value");              
                RoomPstructIdStr += "'" + s + "',";
            }
        });     
        if (RoomPstructIdStr == "") {
            dialogMsg('请选择需要添加的数据！', 0);
            return false;
        }
        $.ajax({
            url: "../../ResourceManage/RS_PStructPublish/GetRoomEntity",          
            data: { queryJson: RoomPstructIdStr },
            type: 'post',
            dataType: "json",
            success: function (item) {
                $("#gridTable")[0].addJSONData(item);
            }
        });
    }

    function btn_del() {       
        var ids = $("#gridTable").jqGrid("getGridParam", "selarrrow");    
        //遍历访问这个集合  
        $(ids).each(function (index, id) {          
            $("#gridTable").delRowData(id);
        });
    }

    function AcceptClick() {
        var obj = $("#gridTable").jqGrid("getRowData");
        if (obj.length < 1) {
            dialogMsg('最少选择一条数据', 0);
            return false;
        }
        var $gridTable = top.frames["Form"].$("#gridTable");
        var GridData = $gridTable.jqGrid("getRowData");
        debugger;
        for (var i = 0; i < GridData.length; i++) {
            var obj = $.grep(obj, function (value) {
                return value.PStructId != GridData[i].PStructId;
            });
        }
        $gridTable.addRowData(($gridTable.jqGrid("getRowData").length + 1), obj);      
        dialogMsg("操作成功。", 1);
        dialogClose();
    }
</script>

<div class="ui-layout" id="layout" style=" width: 100%;">
    <div class="ui-layout-west" style="width: 200px; ">
        <div class="west-Panel">
            <div class="panel-Title" style="padding:0px; text-align:center;">房屋列表</div>
            <div id="itemTree1">
            </div>
        </div>
        <div style="width:80px;height:300px;  position:absolute; top:100px; left:200px;">
            <ul>
                <li><a class="btn btn-default " style="width: 50px; margin: 10px 25px;" onclick="btn_add()"><i class="fa fa-angle-right"></i></a> </li>
                <li><a class="btn btn-default " style="width: 50px; margin: 10px 25px;" onclick="btn_del()"><i class="fa fa-angle-left"></i></a> </li>
            </ul>
        </div>
        <div class="gridPanel" style="width:780px; position:absolute;top:10px;left:300px;">
            <table id="gridTable"></table>
        </div>
    </div>
</div>
